package com.liu.ai.embedding;

import com.liu.ai.store.JdbcTools;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.embedding.*;
import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.ai.ollama.management.ModelManagementOptions;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;

import javax.activation.DataSource;
import java.util.List;

public class EmbeddingDemo {

    public static void main(String[] args) {
        Embedding embedding = getEmbedding("测试向量化");
        float[] output = embedding.getOutput();
    }



    private static Embedding getEmbedding(String str) {
        OllamaApi api = new OllamaApi("http://localhost:11434",
                RestClient.builder(),
                WebClient.builder());

        OllamaOptions embeddingOptions = OllamaOptions.builder()
                .model("zyw0605688/gte-large-zh:latest")
                .build();
        OllamaEmbeddingModel embedding = new OllamaEmbeddingModel(
                api,
                embeddingOptions,
                ObservationRegistry.create(),
                ModelManagementOptions.builder().build());

        EmbeddingOptions options = EmbeddingOptionsBuilder.builder()
                .withModel("zyw0605688/gte-large-zh:latest")
                .withDimensions(1024)
                .build();
        EmbeddingRequest request = new EmbeddingRequest(List.of(str),options);

        EmbeddingResponse call = embedding.call(request);
        System.out.println("result: " + call.getResult());
        return call.getResult();
    }


}
